<template>
    <div>
       <MBX Biao='数据统计' Biao1='数据列表'></MBX>
       <el-card class="mt">
            <div ref='mydom' id="main" style="width: 70%; height: 400px"></div>
       </el-card>
    </div>
</template>

<script>
import * as echarts from 'echarts'
import _ from 'lodash'
import {getSJ} from "@/http/api"

    export default {
        data() {
    return {
      myChart:null,
      options: {
        title: {
          text: "用户来源",
        },

        tooltip: {
          trigger: "axis",
          axisPointer: {
            type: "cross",
            label: {
              backgroundColor: "#E9EEF3",
            },
          },
        },

        grid: {
          left: "3%",
          right: "4%",
          bottom: "3%",
          containLabel: true,
        },

        xAxis: [{ boundaryGap: false }],

        yAxis: [{ type: "value" }],
      },
    };
  },
  components: {},
  mounted(){

    this.getCart()
    //保存当前组件实例
    let _this=this
    window.addEventListener("resize",function(){
      _this.myChart.resize()
    },false);

  },
  methods:{
 async getCart() {
    //获取dom
    const mydom=this.$refs.mydom
    this.myChart = echarts.init(mydom);
    const res = await getSJ()
    const mergeData={...this.options,...res}
    // const result = _.merge(data, this.options);
    const options=mergeData
    //渲染图表
    this.myChart.setOption(options);
  },
  }
  
 
    }
</script>

<style scoped>

</style>